#!/bin/bash

set -e
set -x

ssh-keygen -f /root/.ssh/id_rsa -t rsa -N '' -q
cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
cat > /root/.ssh/config <<EOF
Host *
    StrictHostKeyChecking no
EOF

iplist_path=config
while read -r line
do
    case $line in
        *'#'*)
            continue
        ;;
        *'end'*)
            break
        ;;
        *)
            IFS=',' read -ra parts <<< "$line"
        ;;
    esac
  
    pass="${parts[0]}" 
    address="${parts[1]}"
    hostname="${parts[2]}"
    
    if [ $address ];then
        cat >> /etc/hosts << EOF
$address   $hostname
EOF
    fi
done < $iplist_path

set +x
set +e